<template>
  <!-- <HomePage2></HomePage2> -->

  <div class="task-list">
    <!-- <el-table :data="answer">
            <el-table-column prop="name" label="回复人"></el-table-column>
              <el-table-column prop="message" label="回复"></el-table-column>
              <el-table-column prop="datetime" label="回复时间"></el-table-column>
        </el-table> -->
    <ul v-for="(answer, index) in answer" :key="index">
      <li>{{ answer.name }}</li>
      <li>{{ answer.message }}</li>
    </ul>
  </div>
</template>

<script>
import axios from 'axios'
import { reactive } from 'vue'
import { onMounted } from 'vue'
import { useRouter } from 'vue-router'
// import { routeLocationKey } from 'vue-router';
export default {
  // components: {
  //   HomePage2
  // },

  setup() {
    const data = reactive({
      account: '16057583'
    })
    const tableData = reactive([])
    const answer = reactive([])
    const sumAnswer = reactive([])
    // const gotoLookMessage = () => {
    //   router.push({path:'/Message',params:answer})
    // }
    const getTaskRes = async () => {
      const { data: res } = await axios.post('user/function/checkSendTask', {
        account: data.account
      })
      if (res.code == 200) {
        // tableData.splice(0, tableData.length, ...res.data)
        tableData.splice(
          0,
          tableData.length,
          ...res.data.map((task) => ({
            ...task,
            showAnswer: false
          }))
        )
        // console.log(tableData.length)
        for (const task of tableData) {
          const reqId = task.reqId
          await getAnswer(reqId) // 调用 getAnswer 并传递 reqId
        }
      }
    }
    const getAnswer = async (reqId) => {
      const { data: res } = await axios.post('user/function/checkAnswer', {
        reqId: reqId
      })
      //console.log(res.data)
      // if (res.data != null || undefined) {
      //   answer.splice(
      //     0,
      //     answer.length,
      //     ...res.data.map((answerI) => ({
      //       ...answerI
      //     }))
      //   )

      // } else {
      //   // console.log("暂无回复")
      // }
      // answer=res.data
      // console.log(answer)
      // console.log(reqId)
      // console.log(res.data)
      // answer[reqId] = res.data
      // console.log(res.data)
    }

    const handleClick = (row) => {
      row.showAnswer = !row.showAnswer
    }
    onMounted(getTaskRes)
    onMounted(getAnswer)
    return {
      getTaskRes,
      tableData,
      handleClick,
      getAnswer,
      answer
    }
  }
}
</script>

<style>
.task-list {
  position: relative;
  margin: 0 auto;
  width: 1226px;
  height: 100%;
}
</style>
